<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="/WEB-INF/page-base.tld" prefix="p"%>
<!DOCTYPE html>
<HTML>
  <head>
	<%@ include file="/platform/style.jsp"%>
	<script src="<%=path %>/util/js/combox.js"></script>
	<script src='<%=path %>/util/js/ui.core.js' type='text/javascript'></script>
	<link href='<%=path %>/util/js/dtree/skin/ui.dynatree.css' rel='stylesheet' type='text/css'>
	<script src='<%=path %>/util/js/dtree/jquery.dynatree.js' type='text/javascript'></script>
<script>
	$(function(){
		$("#menutree_admin").dynatree({
			title: "菜单根节点",
			rootVisible: true,
			initAjax: { 
	               url: ctx+"/platform/menu/MenuTreeJson.json" 
				},
			onLazyRead: function(dtnode){
	               dtnode.appendAjax({
	                   url: ctx+"/platform/menu/MenuTreeJson.json?nodeId="+ dtnode.data.key
	               });
			},
			onActivate: function(dtnode){
				$getByName("menuId",$("#menutree_admin_panel")).val(dtnode.data.key);
			}
			
		});
	})
	function menu_addmenu(){
		var values=$getByName("menuId",$("#menutree_admin_panel")).val();
		if(!values){
			$w.infoMsg('请选择上级菜单！');
			return false;
		}
		var str=ctx+"/platform/menu/MenuPage.page?actions=addShow&menuId="+values;
		window.parent.$w.openDialog({url:str,title:"添加菜单",w:490,h:350,afterClose:function(re){
			if(re)
				tree_afterAddNode('menutree_admin');
		}});
	}
	function menu_editmenu(){
		var values=$getByName("menuId",$("#menutree_admin_panel")).val();
		if(values==''){
			$w.infoMsg('请选择菜单！');
			return false;
		}else if(values=='root'){
			$w.infoMsg('不能修改根节点！')
			return false;
		}
		var str=ctx+"/platform/menu/MenuPage.page?actions=updateShow&menuId="+values;
		window.parent.$w.openDialog({url:str,title:"修改菜单",w:490,h:350,afterClose:function(re){
			if(re)
				tree_afterUpdateNode('menutree_admin',re);
		}});
	}
	function menu_delmenu(){
		var values=$getByName("menuId",$("#menutree_admin_panel")).val();
		if(!values){
			window.parent.$w.infoMsg('请选择菜单！');
			return false;
		}else if(values=='root'){
			window.parent.$w.infoMsg('不能删除根节点！')
			return false;
		}
		var urls=ctx+"/platform/menu/MenuPage.page?actions=del&menuId="+values;
		window.parent.$w.confirmMsg("确定删除？", function(r){
			if(r){
			$w.doUrl(urls,{},function(re){
				if(re.state=='ok'){
					tree_afterDelNode("menutree_admin");
					$getByName("deptId",$("#deptmain_div")).val("");
				}
			})
			}
		});
	}
	
	function menu_sortmenu(){
		var values=$getByName("menuId",$("#menutree_admin_panel")).val();
		if(!values){
			$w.infoMsg('请选择上级菜单！');
			return false;
		}
		var path=ctx+"/platform/menu/MenuPage.page?actions=sortShow&parMenuId="+values;
		window.parent.$w.openDialog({url:path,title:"菜单排序",w:274,h:280,afterClose:function(re){
			if(re)
				tree_reloadOpen("menutree_admin");
		}});
	}
</script>
<body class="easyui-layout">
<div data-options="region:'center',border:false">
<div class="ui-toolBar" border="false" id="menutree_admin_panel">
<p:hidden bind="menuId"/>
	<a href="#" class="easyui-linkbutton" onclick="menu_addmenu()" data-options="plain:true,iconCls:'icon_add'">添加</a>
	<a href="#" class="easyui-linkbutton" onclick="menu_editmenu()" data-options="plain:true,iconCls:'icon_edit'">修改</a>
	<a href="#" class="easyui-linkbutton" onclick="menu_delmenu()" data-options="plain:true,iconCls:'icon_del'">删除</a>
	<a href="#" class="easyui-line"></a>
	<a href="#" class="easyui-linkbutton" onclick="menu_sortmenu()" data-options="plain:true,iconCls:'icon_sort'">排序</a>
</div>

<div style="width:100%;height:5px;"></div>
<div id="menutree_admin"></div>
</div>
</body>
</HTML>
